<template>
  <el-container class="home-container">
    <!-- 头部 -->
    <el-header>
      <div class="header-left">
        <span>奖学金评定系统</span>
      </div>
      <div class="header-right">
        <span>欢迎，{{ name }}</span>
        <el-button type="text" @click="logout">退出</el-button>
      </div>
    </el-header>
    
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <el-menu 
          :default-active="activePath" 
          background-color="#333744" 
          text-color="#fff" 
          active-text-color="#409EFF"
          :collapse="isCollapse"
          :collapse-transition="false"
          :unique-opened="true"
          router>
          
          <!-- 首页 -->
          <el-menu-item index="/welcome">
            <i class="el-icon-s-home"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          
          <!-- 根据角色显示不同菜单 -->
          <!-- 管理员菜单 -->
          <template v-if="role === 'ADMIN'">
            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-s-custom"></i>
                <span>用户管理</span>
              </template>
              <el-menu-item index="/user">用户列表</el-menu-item>
            </el-submenu>
            
            <el-submenu index="2">
              <template slot="title">
                <i class="el-icon-s-order"></i>
                <span>奖学金管理</span>
              </template>
              <el-menu-item index="/review">评审管理</el-menu-item>
            </el-submenu>
            
            <el-submenu index="3">
              <template slot="title">
                <i class="el-icon-s-data"></i>
                <span>数据统计</span>
              </template>
              <el-menu-item index="/statistics">奖学金分配</el-menu-item>
            </el-submenu>
            
            <el-menu-item index="/settings">
              <i class="el-icon-setting"></i>
              <span slot="title">系统设置</span>
            </el-menu-item>
          </template>
          
          <!-- 导师菜单 - 默认菜单 -->
          <template v-else>
            <el-menu-item index="/profile">
              <i class="el-icon-user"></i>
              <span slot="title">个人信息</span>
            </el-menu-item>
            
            <el-menu-item index="/student/management">
              <i class="el-icon-s-custom"></i>
              <span slot="title">学生管理</span>
            </el-menu-item>
            
            <el-menu-item index="/political">
              <i class="el-icon-s-flag"></i>
              <span slot="title">思政评分</span>
            </el-menu-item>
            
            <el-menu-item index="/research">
              <i class="el-icon-s-cooperation"></i>
              <span slot="title">科研评分</span>
            </el-menu-item>
            
            <el-menu-item index="/review">
              <i class="el-icon-s-check"></i>
              <span slot="title">奖学金评审</span>
            </el-menu-item>
          </template>
        </el-menu>
      </el-aside>
      
      <!-- 内容区域 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { mapGetters } from 'vuex'

export default {
  name: 'Home',
  data() {
    return {
      isCollapse: false,
      activePath: '/welcome'
    }
  },
  computed: {
    ...mapGetters(['name', 'role'])
  },
  created() {
    this.activePath = this.$route.path
    // 保存激活状态
    window.sessionStorage.setItem('activePath', this.activePath)
  },
  methods: {
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
    },
    logout() {
      this.$confirm('确认退出登录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('logout')
        this.$router.push('/login')
      }).catch(() => {})
    }
  }
}
</script>

<style scoped>
.home-container {
  height: 100%;
}

.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  font-size: 20px;
}

.header-left {
  display: flex;
  align-items: center;
}

.header-right {
  display: flex;
  align-items: center;
}

.header-right span {
  margin-right: 15px;
  font-size: 16px;
}

.el-aside {
  background-color: #333744;
  transition: width 0.3s;
}

.el-menu {
  border-right: none;
}

.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}

.el-main {
  background-color: #eaedf1;
}
</style> 